Sooooo nothing with BEC zones has been promising so far. Let’s try something else. Let’s switch to VRI data and see if amount of mature/old growth forest is related to amount of squirrel in the diet, since squirrels like old forests.
# Load some libraries.
library(tidyverse)
library(landscapemetrics)
library(raster)
library(sf)
# Bring in diet data.
df <- read_csv('../data/interim/camera_corrected.csv', guess_max=7000)
# I had some trouble with readr so I increased the number of rows used to guess.
source('../src/prey_attributes.R')
head(items)
# Calculate proportion of diet made up of squirrel at each site.
sq.mass <- items %>% mutate(mass=as.numeric(mass)) %>%
group_by(site) %>%
mutate(total=sum(mass)) %>%
filter(genus == 'Tamiasciurus') %>%
mutate(amount.sq=sum(mass), prop.sq=amount.sq/total) %>%
dplyr::select(site, prop.sq) %>% distinct()
sq.mass
That’s remarkably consistent.
The next step is to get the amount of mature forest for each of these sites. Unfortunately, the VRI data for Turbid Creek is useless so that drops me down to five sites. But I can pull in the VRI for the others…
# Import transition zone shapefile.
vri <- st_read('../data/external/VRI_camera-sites_2019.shp')
Reading layer `VRI_camera-sites_2019' from data source `C:\Users\Gwyn\sfuvault\productivity-occupancy\data\external\VRI_camera-sites_2019.shp' using driver `ESRI Shapefile'
Simple feature collection with 13321 features and 188 fields
geometry type: POLYGON
dimension: XY
bbox: xmin: 413289.1 ymin: 5428268 xmax: 645675.7 ymax: 5589928
CRS: 32610
Then I need to rasterize it. Which means first I need to break it down into classes so I can assign a raster value. Unfortunately there’s no single field in the VRI data that works for classification. I can break this into:
# Assign to classes.
# Regen/young/mature/old ages come from Zharikov et al. 2007
vri.class <- vri %>% mutate(hab.class=case_when(
# Non-vegetated and water
BCLCS_LV_1 == 'N' & BCLCS_LV_2 == 'W' ~ 1,
# Non-vegetated and not water
BCLCS_LV_1 == 'N' & BCLCS_LV_2 != 'W' ~ 2,
# Vegetated and not trees
BCLCS_LV_1 == 'V' & BCLCS_LV_2 == 'N' ~ 3,
# Vegetated and mixed or deciduous trees
BCLCS_LV_1 == 'V' & BCLCS_LV_4 %in% c('TB', 'TM') ~ 4,
# Vegetated and coniferous trees
BCLCS_LV_4 == 'TC' & PROJ_AGE_1 < 20 ~ 5,
BCLCS_LV_4 == 'TC' & PROJ_AGE_1 >= 20 & PROJ_AGE_1 < 60 ~ 6,
BCLCS_LV_4 == 'TC' & PROJ_AGE_1 >= 60 & PROJ_AGE_1 < 140 ~ 7,
BCLCS_LV_4 == 'TC' & PROJ_AGE_1 >= 140 ~ 8,
TRUE ~ 0
))
# See how it turned out.
vri.class %>% group_by(hab.class) %>% summarise(n())
Simple feature collection with 9 features and 2 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: 413289.1 ymin: 5428268 xmax: 645675.7 ymax: 5589928
CRS: 32610